package com.tencent.yumeko;

import com.google.gson.Gson;
import com.tencent.cloud.polaris.router.spi.SpringWebRouterLabelResolver;
import org.springframework.http.HttpRequest;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

//自定义路由器标签解析器
public class CustomSpringWebRouterLabelResolver implements SpringWebRouterLabelResolver {
    private final Gson gson = new Gson();

    @Override
    public Map<String, String> resolve(HttpRequest request, byte[] body, Set<String> expressionLabelKeys) {
        Map<String, String> labels = new HashMap<>();
        User user = gson.fromJson(new String(body), User.class);

        labels.put("user", user.getName());
        return labels;
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
